<?php
session_start(); 
 $ftp_server="ftp.24-7saddles.com";
 $ftp_user_name="z247s504";
 $ftp_user_pass="PxLpCd07";

 // set up basic connection
 $conn_id = ftp_connect($ftp_server);

 // login with username and password
 $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 


//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 350Kb
$filename = basename($_POST['product_id']."_".$_POST['image_number'].".jpg");
//$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);

//Determine the path to which we want to save this file

	//Live
	//$newname = '/home/z247s504/public_html/images/saddles/'.$filename;

	//Test
	$newname = '/home/z247s504/public_html/images/saddles/'.$filename;

//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname)))
{


//
////Resize the image
//////Limit the image to a maximum size

$orig_image = imagecreatefromjpeg($newname);//Get the uploaded image file name
$image_info = getimagesize($newname); //Get image current size
$width_orig  = $image_info[0]; // current width as found in image file
$height_orig = $image_info[1]; // current height as found in image file
$width = 500; // new image width
$height = 500; // new image height
$width = (($width_orig * $height)/$width_orig); // new image width
$destination_image = imagecreatetruecolor($width, $height);
imagecopyresampled($destination_image, $orig_image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

//If the image being uploaded is larger than 500 x 500
if($width_orig > 500 && $height_orig > 500)
{
// This will just copy the new image over the original at the same filePath.
imagejpeg($destination_image, $newname, 100);
$resizeMessage="Image has been resized to (".$width."px x ".$height."px)";
}

//
////
//////End Image Resize


//Go back to the products page   
header("Location: webmaster_amend_products.php?File uploaded");


}
else
{
$_SESSION['updateMessage'] = "Error";    
header("Location: webmaster_edit_products.php?Error");
}
} else

{
$_SESSION['updateMessage'] = "Error";    
header("Location: webmaster_edit_products.php?Error"); 	
}
?>